import {GET_DEFAULT_ADDRESS,GET_HANDLE_CONDITION} from "./actionsTypes";
export const getDefaultAddress = data => ({type: GET_DEFAULT_ADDRESS, data: data}); //默认地址
export const getCondition = data => ({type: GET_HANDLE_CONDITION, data: data}); //办理条件


import homeService from  '../services/homeService';
import {Toast} from 'antd-mobile'

//获取默认地址
export const defaultAddress=(data,callBack)=>{
    return (dispatch, getState)=> {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        homeService.defaultAddress(data).then(resultData => {
            Toast.hide();
            if (resultData.code == 1000) {
                dispatch(getDefaultAddress(resultData.body))
                callBack&&callBack()
            } else {
                Toast.info(resultData.msg, 1)
            }
        },()=>{
			Toast.hide(); 
            Toast.info("系统繁忙，请稍后再试");
		})
    }
}

//获得办理条件
export const condition=(data,callBack)=>{
    return (dispatch, getState)=> {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        homeService.condition(data).then(resultData => {
            Toast.hide();
            if (resultData.code == 1000) {
                 dispatch(getCondition(resultData.body))
                callBack&&callBack()
            } else {
                Toast.info(resultData.msg, 1)
            }
        },()=>{
			Toast.hide(); 
            Toast.info("系统繁忙，请稍后再试");
		})
    }
}

//确认订单
export const confirmOrder=(data,callBack)=>{
    return (dispatch, getState)=> {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        homeService.confirmOrder(data).then(resultData => {
            Toast.hide();
            if (resultData.code == 1000) {
                //  dispatch(getCondition(resultData.body))
                callBack&&callBack(resultData.body)
            } else {
                Toast.info(resultData.msg, 1)
            }
        },()=>{
			Toast.hide(); 
            Toast.info("系统繁忙，请稍后再试");
		})
    }
}

